package com.atguigu.controller;

import com.atguigu.bean.Department;
import com.atguigu.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    @GetMapping("/depts")
    public List<Department> getDepts() {
        return departmentService.getDepts();
    }

    @GetMapping("/dept/{id}")
    public Department getDeptById(@PathVariable("id") Integer id) {
        return departmentService.getDeptById(id);
    }

    @RequestMapping("/dept/add")
    public Department addDept(Department dept) {
        departmentService.addDept(dept);
        return dept;
    }

    @RequestMapping("/dept/edit")
    public Department editDept(Department dept) {
        departmentService.editDept(dept);
        return dept;
    }

    @RequestMapping("/dept/delete/{id}")
    public int deleteDept(@PathVariable("id") Integer id) {
        return departmentService.deleteDept(id);
    }
}
